package com.oocl.homework.crm.command;


import com.oocl.homework.crm.datastruct.Executeable;
import com.oocl.homework.crm.model.Filterable;
import com.oocl.homework.crm.model.Result;


public class AddCommand<T> extends Command<T>{

	public AddCommand(String command) {
		super(command);
	}

	@Override
	public void filter(Filterable filterable) {
		super.filter(filterable);
		if(result.getCode()==-1){
			return ;
		}else{
			if(command.split(" ").length>2){
				result.setCode(-1);
				result.setMessage("Unrecognized command:"+command);
				return;
			}
			splitCommandParameterAttributes();
			if(result.getCode()==-1){
				return ;
			}
			Result filterResult = filterable.filter(getCommandParameterAttributes());
			if (filterResult.getCode()==-1) {
				result =  filterResult;
				return;
			}
		}
		
		String[] attributes = getCommandParameterAttributes();
		for (int i = 0; i < attributes.length; i++) {
			if (attributes[i].equals("id")) {
				result.setCode(-1);
				result.setMessage("id is not allow");
			}
		}
		
	}

	@Override
	public void executeCommand(Executeable<T> executeable,T t) {
		super.executeCommand(executeable, t);
		executeable.add(t);
		
	}
	
	@Override
	public void display() {
		super.display();
		CommandDoc.printAddCommandHelp();
		
	}

	

}
